package com.shell.arouter.demo.permission;

import android.view.View;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.durian.base.permission.RequestExecutor;
import com.durian.base.permission.SoonPermission;
import com.durian.base.permission.listener.OnPermissionListener;
import com.durian.base.permission.listener.SimplePermissionListener;
import com.durian.base.permission.task.IPermissionTask;
import com.durian.base.utils.AndroidInfoUtils;
import com.durian.ui.factory.ViewTools;
import com.henanjianye.soon.communityo2o2.R;
import com.shell.arouter.ui.FragmentCommon;

import static com.shell.arouter.extend.ARouterPathKt.PATH_FRAGMENT_PERMISSION;

/**
 * 说明：FragmentPermission
 * <p/>
 * 作者：fanly
 * <p/>
 * 类型：Class
 * <p/>
 * 时间：2019-11-13 11:51
 * <p/>
 * 版本：version 1.0
 */
@Route(path = PATH_FRAGMENT_PERMISSION)
public class FragmentPermission extends FragmentCommon {

    TextView tvCode;

    @Override
    public boolean isShowTitleBar() {
        return true;
    }

    @Override
    public boolean isShowTitleBarBack() {
        return true;
    }

    @Override
    public String bindTitleBarText() {
        return "AndPermission";
    }
    @Override
    protected int getRootViewResID() {
        return R.layout.fragment_permission;
    }
    @Override
    protected void onFirstUserVisible() {
        super.onFirstUserVisible();
        tvCode = findViewById(R.id.tv_code);

        ViewTools.setText(tvCode, AndroidInfoUtils.getTerminalCode());

        findViewById(R.id.btn_read_phone_state).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SoonPermission.with(FragmentPermission.this)
                        .notification()
                        .setPermissionListener(new SimplePermissionListener() {
                            @Override
                            public void onDenied(RequestExecutor executor, IPermissionTask task) {
                                shortToast("通知获取拒绝");
                            }

                            @Override
                            public void onGranted() {
                                shortToast("通知获取成功");
                            }

                            @Override
                            public void onCancel() {
                                shortToast("通知获取取消");
                            }
                        })
                        .start();
            }
        });
        findViewById(R.id.btn_camera_permission).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SoonPermission.with(FragmentPermission.this)
                        .camera()
                        .setPermissionListener(new SimplePermissionListener() {
                            @Override
                            public void onDenied(RequestExecutor executor, IPermissionTask task) {
                                shortToast("相机权限获取拒绝");
                            }

                            @Override
                            public void onGranted() {
                                shortToast("相机权限获取成功");
                            }

                            @Override
                            public void onCancel() {
                                shortToast("相机权限获取取消");
                            }
                        })
                        .start();
            }
        });
        findViewById(R.id.btn_location_permission).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SoonPermission.with(FragmentPermission.this)
                        .location()
                        .setPermissionListener(new SimplePermissionListener() {
                            @Override
                            public void onDenied(RequestExecutor executor, IPermissionTask task) {
                                shortToast("定位权限获取拒绝");
                            }

                            @Override
                            public void onGranted() {
                                shortToast("定位权限获取成功");
                            }

                            @Override
                            public void onCancel() {
                                shortToast("定位权限获取取消");
                            }
                        })
                        .start();
            }
        });
        findViewById(R.id.btn_lianxiren_permission).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SoonPermission.with(FragmentPermission.this)
                        .contacts()
                        .setPermissionListener(new SimplePermissionListener() {
                            @Override
                            public void onDenied(RequestExecutor executor, IPermissionTask task) {
                                shortToast("通讯录权限获取拒绝");
                            }

                            @Override
                            public void onGranted() {
                                shortToast("通讯录权限获取成功");
                            }

                            @Override
                            public void onCancel() {
                                shortToast("通讯录权限获取取消");
                            }
                        })
                        .start();
            }
        });
        findViewById(R.id.btn_camera_location_store_permission).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SoonPermission.with(FragmentPermission.this)
                        .storage()
                        .camera()
                        .setPermissionListener(new SimplePermissionListener() {
                            @Override
                            public void onDenied(RequestExecutor executor, IPermissionTask task) {
                                shortToast("存储-相机-权限获取拒绝");
                            }

                            @Override
                            public void onGranted() {
                                shortToast("存储-相机-权限获取成功");
                            }

                            @Override
                            public void onCancel() {
                                shortToast("存储-相机-权限获取取消");
                            }
                        })
                        .start();
            }
        });
        findViewById(R.id.btn_camera_location_store_permission_always).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SoonPermission.with(FragmentPermission.this)
                        .camera()
                        .location()
                        .storage()
                        .setPermissionListener(new SimplePermissionListener() {
                            @Override
                            public void onDenied(RequestExecutor executor, IPermissionTask task) {
                                shortToast("相机-定位-存储-权限循环模式获取拒绝");
                            }

                            @Override
                            public void onGranted() {
                                shortToast("相机-定位-存储-权限循环模式获取成功");
                            }

                            @Override
                            public void onCancel() {
                                shortToast("相机-定位-存储-权限循环模式获取取消");
                            }
                        })
                        .start();
            }
        });
    }

}
